/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dao;

import java.sql.ResultSet;
import java.util.ArrayList;
import model.dao.util.MySQLDataAccessHelper;
import model.pojo.baivietPOJO;

/**
 *
 * @author lethong
 */
public class baivietDAO {
    public static ArrayList<baivietPOJO> getlistBaiviet(int loai) throws Exception
    {
        ArrayList<baivietPOJO> ds=new ArrayList<baivietPOJO>();
        try
        {
            String sql="Select * From baiviet where idLoaibaiviet="+loai;
            MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
            helper.open();
            ResultSet rs=helper.executeQuery(sql);
            while(rs.next())
            {
                baivietPOJO s=new baivietPOJO();
                s.setID(rs.getInt("id"));
                s.setTenbaiviet(rs.getString("tenbaiviet"));
                s.setNoidung(rs.getString("noidung"));
                s.setLoaibaiviet(rs.getInt("idLoaibaiviet"));
                ds.add(s);
            }
            helper.close();
        }catch(Exception ex)
        {
            throw ex;
        }
        return ds;
    }
    
    public static ArrayList<baivietPOJO> getlistBaiviet_Thongbao(int loai) throws Exception
    {
        ArrayList<baivietPOJO> ds=new ArrayList<baivietPOJO>();
        try
        {
            String sql="Select * From baiviet where idLoaibaiviet="+loai+" Order by ID desc";
            MySQLDataAccessHelper helper=new MySQLDataAccessHelper();
            helper.open();
            ResultSet rs=helper.executeQuery(sql);
            while(rs.next())
            {
                baivietPOJO s=new baivietPOJO();
                s.setID(rs.getInt("id"));
                s.setTenbaiviet(rs.getString("tenbaiviet"));
                s.setNoidung(rs.getString("noidung"));
                s.setLoaibaiviet(rs.getInt("idLoaibaiviet"));
                ds.add(s);
            }
            helper.close();
        }catch(Exception ex)
        {
            throw ex;
        }
        return ds;
    }
}
